<template>
	<view class="container">
		<!-- s收货地址 -->
		<view class="address">
			<view class="address_info">
				<label for="">收件人:悟空</label>
				<label for="">{{phone}}</label>
			</view>
			<view class="address_res">
				收货地址：<label for="">花果山水帘洞27号</label>
			</view>
		</view>

		<!-- 商品信息 -->
		<view class="carts">

			<view class="cartsInfo" v-for="(item,index) in list" :key="index">
				<!-- 70px -->
				<view class="carts_detail">
					<view class="carts_image">
						<image :src="item.img" mode=""></image>
					</view>
					<view class="carts_name">
						<view for="" style="font-size: 30rpx;">{{item.goodsname}}</view>
						<view for="" style="font-size: 26rpx; color: #C0C0C0;">规格:300</view>
					</view>
					<view class="carts_price">
						<label for="">￥ {{item.price}}</label>
					</view>
				</view>
				<!-- 50px -->
				<view class="cart_num">
					<view class="">
						购买数量：
					</view>
					<view class="">
						<label for="" disabled v-if="item.num<=1" class="jian">-</label>
						<label for="" @click="reduce(index)" v-if="item.num>1" class="jian">-</label>
						<label for="" class="num">{{item.num}}</label>
						<label for="" @click="add(index)" class="jia">+</label>
					</view>
				</view>
				<!-- 横线 -->
				<view class="xian"></view>
			</view>

			<!-- 50px -->
			<view class="kuaidi">
				<label for="">配送方式</label>
				<label for="">XX快递</label>
			</view>
		</view>

		<!-- 优惠券 -->
		<view class="yhquan">
			<label for="">优惠券</label>
			<label for="" style="margin-right: 40rpx;">无可用</label>
		</view>
		<!-- jifen积分 -->
		<view class="jifen">
			<view class="use">
				<label for="">使用积分</label>
			</view>
			<view class="input" style="margin-right: 40rpx;">
				<input type="text" value="" placeholder="输入积分" />
				<label for="" class="input_use">使用</label>
				<label for="" class="input_keyi">可使用50积分</label>
			</view>
		</view>

		<!-- 具体详细 -->
		<view class="resDetail">
			<view class="">
				<label for="">商品金额</label>
				<label for="" style="margin-right:40rpx;color:red">￥{{allprice}}</label>
			</view>
			<view class="">
				<label for="">运费</label>
				<label for="" style="margin-right:40rpx;color:red">+￥12.00</label>
			</view>
			<view class="">
				<label for="">优惠券</label>
				<label for="" style="margin-right:40rpx;color:red">-￥0.00</label>
			</view>
			<view class="">
				<label for="">会员优惠</label>
				<label for="" style="margin-right:40rpx;color:red">-￥0.00</label>
			</view>
			<view class="">
				<label for="">积分抵扣</label>
				<label for="" style="margin-right:40rpx;color:red">-￥0.00</label>
			</view>
		</view>
		<!-- 实付金额 -->
		<view class="sfje">
			实付金额：<label for="" style="color:red">￥{{allprice+12}}</label>
		</view>

		<!-- 确认订单按钮 -->
		<view class="btn">
			<!-- 点击提交订单按钮，发起支付请求 -->
			<button type="primary" @click="pay">提交订单</button>
		</view>
	</view>
</template>

<script>
	import {baseUrl} from "../../utils/config.js"
	export default {
		onLoad() {
			let result = JSON.parse(uni.getStorageSync("login"))
			this.phone = result.phone
			this.token = result
			if(uni.getStorageSync("goods")){
				this.list = uni.getStorageSync("goods")
			}else{
				this.list.push(uni.getStorageSync("goodstwo"))
				this.list.map(item=>{
					item.num=0
				})
			}
			console.log(this.list);
			
			
			
		    uni.removeStorageSync('goods')
			console.log(this.token);
		},
		data() {
			return {
				phone: "",
				num: 1,
				list: [],
				token: ""
			}
		},
		computed: {
			allprice() {
				var result = 0
				this.list.forEach(item => {
					result += item.price * item.num
				})
				return result
			}
		},
		methods: {
			add(index) {
				this.list[index].num++
				console.log(this.list);
			},
			reduce(index) {
				this.list[index].num--
			},
			async pay() {
				var uid = this.token.uid
				var addtime = new Date().getTime()
				var countnumber = this.list.length
				var arr = []
				this.list.map(item => {
					return arr.push(item.id)
				})
				// console.log(arr.join(","));
				var idstr = arr.join(",")
				
				var ui = {
					uid,
					username: "王",
					userphone: this.phone,
					address: "河南省南阳市",
					countmoney: this.allprice,
					countnumber,
					addtime
				}
				var params=JSON.stringify(ui)
				let result = await this.$http("/api/orderadd", "get", {
					params,
					idstr
				}, this.token.token)
				console.log(result);
				// uni.showToast({
				// 	title:"提交成功，我的/全部订单中查看"
				// })
				// setTimeout(()=>{
				uni.reLaunch({
					url:"../cart/cart?id="+1
				})	
				// },2000)
				
			}
		}
	}
</script>
<style>
	@import url("../../common/css/confirm.css");
</style>
